﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Interactivity;
using nRoute.Components;
#if (WINRT)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;
using nRoute.Behaviors.Interactivity;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Controls;
#else
using System.Windows.Markup;
using System.Windows.Controls;
using System.Windows.Data;
#endif

namespace nRoute.Behaviors
{
    public class ExecuteVisualCommandAction
#if (WINRT)
        : TriggerAction<FrameworkElement>
#else
        : TriggerAction<UIElement>
#endif
    {
        public static readonly DependencyProperty VisualCommandProperty =
            DependencyProperty.Register("VisualCommand", typeof(VisualCommandBase), typeof(ExecuteVisualCommandAction),
            new PropertyMetadata(Utilities.Compatability.DP_UNSET_VALUE));

#region Properties

        [Category("Common Properties")]
        [CustomPropertyValueEditor(CustomPropertyValueEditor.PropertyBinding)]
        public VisualCommandBase VisualCommand
        {
            get { return (VisualCommandBase)GetValue(VisualCommandProperty); }
            set { SetValue(VisualCommandProperty, value); }
        }

#if (WINRT)

        [Category("Common Properties")]
        [CustomPropertyValueEditor(CustomPropertyValueEditor.PropertyBinding)]
        public Binding VisualCommandBinding
        {
            get { return GetBinding(VisualCommandProperty); }
            set { SetBinding<VisualCommandBase>(VisualCommandProperty, value); }
        }

#endif

#endregion

#region Overrides

        protected override void Invoke(object parameter)
        {
            if (this.VisualCommand != null && this.VisualCommand.IsEnabled) this.VisualCommand.Execute();
        }

#endregion

    }
}
